<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="下单编号" prop="orderSn">
        <el-input
          v-model="queryParams.orderSn"
          placeholder="请输入下单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="下单编号" align="center" prop="orderSn" />
      <el-table-column label="成本" align="center" prop="mallAllCostPrice" />
      <el-table-column label="销售总额" align="center" prop="mallAllPayPrice" />
      <el-table-column label="利润率" align="center" prop="mallProfitRate">
        <template slot-scope="scope">
          <span>{{ scope.row.mallProfitRate }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="最小利润率" align="center" prop="minProfitRate">
        <template slot-scope="scope">
          <span>{{ scope.row.minProfitRate }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="最大利润率" align="center" prop="maxProfitRate">
        <template slot-scope="scope">
          <span>{{ scope.row.maxProfitRate }}%</span>
        </template>
      </el-table-column>
      <el-table-column label="上架状态" align="center" prop="isOnSale">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.isOnSale == 1">在售</el-tag>
          <el-tag type="danger" v-if="scope.row.isOnSale == 2">下架</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="下架的商品名称" align="center" prop="goodsName" />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { profitRuleList } from "@/api/newGoods/profitRules";
export default {
  name: "profitRulesList",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 提交按钮loading
      submitLoading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined,
      },

      btnLoad: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      profitRuleList(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.postId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
  },
};
</script>
